import React, { useState, useCallback } from 'react'

export default function App() {
  console.log('test渲染了')
  const [count, setCount] = useState(0)

  // useCallback会缓存传入的函数.让函数只创建一次
  // 注意: 如果不在第二个参数传入空数组,则还是会重复的创建函数
  const handle = useCallback(() => {
    console.log(count)
    setCount((count) => {
      return count + 1
    })
    // setCount(count + 1)
  }, [])

  return (
    <div>
      <div>{count}</div>
      <button onClick={handle}>按钮</button>
    </div>
  )
}
